﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using jsGotoDefinition.VS2010.Helpers;

namespace jsGotoDefinition.VS2010
{



    public delegate void DefinitionDblClickedEventHandler(object sender, FindResult findresult);

    /// <summary>
    /// Interaction logic for MyControl.xaml
    /// </summary>
    public partial class JSDefinitionControl : UserControl
    {
        public event DefinitionDblClickedEventHandler DefinitionDblClicked;

        public JSDefinitionControl()
        {
            InitializeComponent();
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1300:SpecifyMessageBoxOptions")]
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(string.Format(System.Globalization.CultureInfo.CurrentUICulture, "We are inside {0}.button1_Click()", this.ToString()),
                            "My Tool Window");

        }

        public void bindResults(FindResultCollection results) {
            if (results.Count == 0)
                tabItemDefinitions.Header = "Definitions found (0)";
            else
                tabItemDefinitions.Header = "Definitions found (" + results.Count.ToString() + ")";
            dataGridDefinitions.ItemsSource = results;           
        }

        public void bindErrors(SearchErrorCollection errors) {
            if (errors.Count==0)
                tabItemErrors.Header = "No Errors";
            else
                tabItemErrors.Header = "Errors (" + errors.Count.ToString() + ")";
            dataGridErrors.ItemsSource = errors;
        }

        private void dataGridDefinitions_SelectionChanged(object sender, SelectionChangedEventArgs e) {
            //DataRowView dr = (DataRowView)dataTaskList.SelectedItem;
            //common.selectedTask = dr["id"].ToString();
        }

        private void dataGridDefinitions_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
            if (dataGridDefinitions.SelectedValue != null) {
                if (this.DefinitionDblClicked != null) {
                        this.DefinitionDblClicked(this, (FindResult)(dataGridDefinitions.SelectedValue));
                }                    
            }
        }
    }
}